import { loginAPI,getProfileAPI } from '@/api/user'
export default {
  namespaced: true,
  state() {
    return {
      token: '',
      profile: {},
      flag: true,
      txt:'添加月卡',
      txtStr:"最新一次月卡缴费信息",
      disab:true,
      
    }
  },
  mutations: {
    clearUserInfo(state) {
      // 清除Token
      state.token = ''
      state.profile = {}
  },
    setProfile(state, profile) {
      state.profile = profile
    },
    setToken(state, token) {
      state.token = token
    },
    setFlag(state, flag) {
      state.flag = flag
    }
    ,
    setTxt(state, txt) {
      state.txt = txt
    },
    setDisab(state, disab) {
      state.disab = disab
    },
    setTxtStr(state, txtStr) {
      state.txtStr = txtStr
    }
  },
  actions: {
    async getProfile(ctx) {
      const res = await getProfileAPI()
      ctx.commit('setProfile', res.data)

       // return后，可以直接在  const perms = await store.dispatch('user/getUserProfile')
      // 时接收到返回的数据
      return res.data.permissions 
    },
    async loginAction(ctx, userInfo) {
      console.log(userInfo);
      
      let res = await loginAPI(userInfo)
      ctx.commit('setToken', res.data.token)
    }
  }
}
